<template>
  <div style="margin: 30px">
    <a-form :label-col="labelCol" :wrapper-col="wrapperCol" :rules="rules">
      <a-form-item label="单次提现金额">
        <a-radio-group v-model:value="type" name="radioGroup" @change="change">
          <a-radio value="1">
            满<a-input-number
              style="margin: 0 10px"
              v-model:value="form.minPrice"
              size="small"
              :min="0.1"
              :max="999999"
              :disabled="disabled"
            />元时可提现
          </a-radio>
          <a-radio value="2">暂不设置</a-radio>
        </a-radio-group>
      </a-form-item>
      <a-form-item label="单日提现上限">
        <a-radio-group
          v-model:value="type1"
          name="radioGroup"
          @change="change1"
        >
          <a-radio value="1">
            限<a-input-number
              style="margin: 0 10px"
              v-model:value="form.maxPrice"
              size="small"
              :min="1"
              :max="999999"
              :disabled="disabled1"
            />元时不可提现
          </a-radio>
          <a-radio value="2">暂不设置</a-radio>
        </a-radio-group>
      </a-form-item>
      <a-form-item label="单日提现次数" @change="change2">
        <a-radio-group v-model:value="type2" name="radioGroup">
          <a-radio value="1">
            限<a-input-number
              style="margin: 0 10px"
              v-model:value="form.number"
              size="small"
              :min="1"
              :max="999999"
              :disabled="disabled2"
            />次时不可提现
          </a-radio>
          <a-radio value="2">暂不设置</a-radio>
        </a-radio-group>
      </a-form-item>
    </a-form>
    <a-row style="margin-top: 100px">
      <a-col :span="4" :offset="8">
        <a-button
          type="primary"
          size="large"
          @click="save"
          v-has="{ a: $route, b: 2 }"
          class="d-a-center"
          >保存</a-button
        >
      </a-col>
    </a-row>
  </div>
</template>
<script>
import { defineComponent, reactive, ref } from "vue";
import {
  selectWithdrawDeposit,
  updateWithdrawDeposit,
} from "@/api/buisness/index";
import { message, Modal } from "ant-design-vue";
import { useModal } from "@/hooks"

export default {
  setup() {
    const form = reactive({ maxPrice: "", minPrice: "", number: "" });
    const type = ref("1");
    const type1 = ref("1");
    const type2 = ref("1");
    const disabled = ref(false);
    const disabled1 = ref(false);
    const disabled2 = ref(false);
    const rules = {
      value: [{ required: true, message: "请填写原因!", trigger: "blur" }],
    };
    const obj = ref("");

    const save = async () => {
      const {closeModal} = useModal.confirm({
        title: "确认修改当前提现设置吗?",
        onOk: async () => {
          let res = await updateWithdrawDeposit(form);
          if (res.success) {
            message.success("修改成功");
            init();
            closeModal()
          }
        },
        onCancel() {
          init();
          closeModal()
        },
      });
    };
    const change = (e) => {
      console.log(e, "版本是");
      if (e.target.value == 2) {
        form.minPrice = "";
        disabled.value = true;
      } else {
        disabled.value = false;
      }
    };
    const change1 = (e) => {
      console.log(e, "版本是");
      if (e.target.value == 2) {
        form.maxPrice = "";
        disabled1.value = true;
      } else {
        disabled1.value = false;
      }
    };
    const change2 = (e) => {
      console.log(e, "版本是");
      if (e.target.value == 2) {
        form.number = "";
        disabled2.value = true;
      } else {
        disabled2.value = false;
      }
    };
    init();
    async function init() {
      let res = await selectWithdrawDeposit();
      if (res.success) {
        if (!res.object.minPrice) {
          type.value = "2";
          disabled.value = true;
        } else {
          form.minPrice = res.object.minPrice;
          disabled.value = false;
        }
        if (!res.object.maxPrice) {
          type1.value = "2";
          disabled1.value = true;
        } else {
          form.maxPrice = res.object.maxPrice;
          disabled1.value = false;
        }
        if (!res.object.number) {
          type2.value = "2";
          disabled2.value = true;
        } else {
          form.number = res.object.number;
          disabled2.value = false;
        }
      }
    }
    return {
      obj,
      form,
      rules,
      labelCol: { style: { fontWeight: "bolder" } },
      wrapperCol: { offset: 1 },
      save,
      type,
      type1,
      type2,
      change1,
      change,
      change2,
      disabled,
      disabled1,
      disabled2,
    };
  },
};
</script>
